www.gusucode.com > VC++ SuperReport 超级报表控件源码程序 > VC++ SuperReport 超级报表控件源码程序\code\testReportDlg.cpp
//Download by http://www.NewXing.com // testReportDlg.cpp : implementation file // #include "stdafx.h" #include "testReport.h" #include "testReportDlg.h" #include "ViewReport.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestReportDlg dialog CTestReportDlg::CTestReportDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestReportDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTestReportDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTestReportDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestReportDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTestReportDlg, CDialog) //{{AFX_MSG_MAP(CTestReportDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_REPORT1, OnReport1) ON_BN_CLICKED(IDC_REPORT2, OnReport2) ON_BN_CLICKED(IDC_REPORT3, OnReport3) ON_BN_CLICKED(IDC_REPORT4, OnReport4) ON_BN_CLICKED(IDC_REPORT5, OnReport5) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestReportDlg message handlers BOOL CTestReportDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon SetAccessODBC("menu"); SetAccessODBC("cwgl"); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CTestReportDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CTestReportDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CTestReportDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CTestReportDlg::OnReport1() { CViewReport lp; lp.AddRecord("标题一|标题二|标题三|标题四|标题五|标题六|标题七|标题八|标题九|"); int i=0; while((i++)<60) lp.AddRecord("123123123|123123123|123123123|123123123|123123123|123123123|123123123|123123123|123123123|"); lp.SetTheme("office2003"); lp.SetWindowTitle("test"); lp.AutoSizeWidth(); lp.SetWindowHeight(500); lp.Display(); } void CTestReportDlg::OnReport2() { CViewReport vrp; vrp.SetReportMode(1); if(!vrp.InitTemplate("2")) return; vrp.SetTemplateData("Title","北京建行会计报表"); vrp.SetTemplateData("Data0","密云支行南大街分理"); vrp.SetTemplateData("Data1","密云南大街"); vrp.SetTemplateData("Data2","北京建行分支机构"); int i=0; while(i<15) { vrp.SetTemplateData("Data00","正常贷款"); vrp.SetTemplateData("Data01","2002/%02d/01",i); vrp.SetTemplateData("Data02","%d%d%03d",i,i,i); vrp.SetTemplateData("Data03","2001/%02d/21",i); vrp.SetTemplateData("Data04","%04d%d%03d",i,i,i); vrp.RepeatCurrentLine(); i++; } vrp.SetTheme("office2003"); vrp.WriteTemplateFile(); vrp.SetWindowTitle("测试报表1"); vrp.Display(); } void CTestReportDlg::OnReport4() { CViewReport nr; nr.SetReportMode(1); if(!nr.InitTemplate("3")) return; long rownum=0; long pagenum=1; long linenum=0; int printLine=0; int pageLine=15; while(rownum<100) { rownum+=1; linenum+=1; if(printLine/pageLine>0) { printLine=0; nr.WriteTemplateFile(); nr.SetFormFeed(); pagenum+=1; linenum=1; } printLine+=1; nr.SetTemplateData("rownum","%ld",rownum); //行数 nr.SetTemplateData("linenum","%ld",linenum); //当前页的行数 nr.SetTemplateData("pagenum","%ld",pagenum); //页数 nr.SetTemplateData("sysdate","%s",GetSysTime()); //系统时间 nr.SetTemplateData("systime","%s",GetSysTime()); //系统时间 nr.SetTemplateData("czy","测试员%04d",rownum); //操作员 nr.SetTemplateData("gzrq","2007/05/15"); //工作日期 nr.SetTemplateData("gzsj","%s",GetSysTime()); //机构名称 nr.SetTemplateData("gznr","测试报表%d",rownum); //系统日期 nr.RepeatCurrentLine(); } nr.SetTheme("office2003"); nr.SetWindowTitle("测试报表2"); nr.WriteTemplateFile(); nr.SetPrintInfo("","",""); nr.Display(); } void CTestReportDlg::OnReport3() { //需要ODBC数据源 CViewReport nr; nr.SetTheme("office2003"); nr.DefineReport(); } void CTestReportDlg::OnReport5() { char gw[21],jdy[40]; char qs[11],jqywl[21]; long sjywl,ylerr,elerr,slerr,hjerr; double sjccl,jqccl; CViewReport vrp; vrp.SetReportMode(1); if(!vrp.InitTemplate("岗位业绩统计表")) return; long xj_sjywl,xj_ylerr,xj_elerr,xj_slerr,xj_hjerr; long zj_sjywl,zj_ylerr,zj_elerr,zj_slerr,zj_hjerr; double xj_jqywl,zj_jqywl,xj_qs; xj_sjywl=xj_ylerr=xj_elerr=xj_slerr=xj_hjerr=0; zj_sjywl=zj_ylerr=zj_elerr=zj_slerr=zj_hjerr=0; xj_jqywl=zj_jqywl=xj_qs=0.00; CString prevGW=""; int newPageLine=27; int printLine=0; int line=80; while((line--)>0) { sprintf(gw,"岗位%d",line/10); sprintf(jdy,"0000%d",line); sprintf(qs,"0.%d",line/5); sprintf(jqywl,"%d",line*2); sjywl=line*2; ylerr=line/4; elerr=line/20; slerr=line/30; hjerr=ylerr+elerr+slerr; printLine+=1; if(prevGW=="") prevGW=gw; if(prevGW!=gw) { vrp.SetTemplateData("sjywl0","%ld",xj_sjywl); vrp.SetTemplateData("qs0","%.2f",xj_qs); vrp.SetTemplateData("jqywl0","%.2f",xj_jqywl); vrp.SetTemplateData("yl0","%ld",xj_ylerr); vrp.SetTemplateData("el0","%ld",xj_elerr); vrp.SetTemplateData("sl0","%ld",xj_slerr); vrp.SetTemplateData("hj0","%ld",xj_hjerr); sjccl=jqccl=0.00; if(xj_sjywl) sjccl=double(xj_hjerr)/xj_sjywl; if(xj_jqywl) jqccl=double(xj_hjerr)/xj_jqywl; vrp.SetTemplateData("sjccl0","%.2f",sjccl*1000); vrp.SetTemplateData("jqccl0","%.2f",jqccl*1000); vrp.RepeatCurrentLine(); vrp.RepeatRowSpan(); printLine+=1; if(printLine/newPageLine>0) { printLine=0; vrp.SetTemplateData("zj","转下页"); vrp.SetTemplateData("sjywl1","-"); vrp.SetTemplateData("qs1","-"); vrp.SetTemplateData("jqywl1","-"); vrp.SetTemplateData("yl1","-"); vrp.SetTemplateData("el1","-"); vrp.SetTemplateData("sl1","-"); vrp.SetTemplateData("hj1","-"); vrp.SetTemplateData("sjccl1","-"); vrp.SetTemplateData("jqccl1","-"); vrp.RepeatCurrentLine(); vrp.WriteTemplateFile(); vrp.SetFormFeed(); } xj_sjywl=xj_ylerr=xj_elerr=xj_slerr=xj_hjerr=0; xj_jqywl=xj_qs=0.00; prevGW=gw; } vrp.SetTemplateData("jdrq","%s至%s",GetSysDate(),GetSysDate()); vrp.SetTemplateData("cprq","%s至%s",GetSysDate(),GetSysDate()); vrp.SetTemplateData("dyrq","%s",GetSysDate()); vrp.SetTemplateData("gw","%s",gw); vrp.SetTemplateData("jdy","%s",jdy); vrp.SetTemplateData("sjywl","%ld",sjywl); vrp.SetTemplateData("qs","%.2f",atof(qs)); vrp.SetTemplateData("jqywl","%.2f",atof(jqywl)); vrp.SetTemplateData("yl","%ld",ylerr); vrp.SetTemplateData("el","%ld",elerr); vrp.SetTemplateData("sl","%ld",slerr); vrp.SetTemplateData("hj","%ld",hjerr); sjccl=jqccl=0.00; if(sjywl) sjccl=double(hjerr)/sjywl; if(atof(jqywl)) jqccl=double(hjerr)/atof(jqywl); vrp.SetTemplateData("sjccl","%.2f",sjccl*1000); vrp.SetTemplateData("jqccl","%.2f",jqccl*1000); vrp.RepeatCurrentLine(); xj_sjywl+=sjywl; xj_jqywl+=atof(jqywl); xj_ylerr+=ylerr; xj_elerr+=elerr; xj_slerr+=slerr; xj_hjerr+=hjerr; xj_qs=atof(qs); zj_sjywl+=sjywl; zj_jqywl+=atof(jqywl); zj_ylerr+=ylerr; zj_elerr+=elerr; zj_slerr+=slerr; zj_hjerr+=hjerr; } vrp.SetTemplateData("sjywl0","%ld",xj_sjywl); vrp.SetTemplateData("qs0","%.2f",atof(qs)); vrp.SetTemplateData("jqywl0","%.2f",xj_jqywl); vrp.SetTemplateData("yl0","%ld",xj_ylerr); vrp.SetTemplateData("el0","%ld",xj_elerr); vrp.SetTemplateData("sl0","%ld",xj_slerr); vrp.SetTemplateData("hj0","%ld",xj_hjerr); sjccl=double(xj_hjerr)/xj_sjywl; jqccl=double(xj_hjerr)/xj_jqywl; vrp.SetTemplateData("sjccl0","%.2f",sjccl*1000); vrp.SetTemplateData("jqccl0","%.2f",jqccl*1000); vrp.RepeatCurrentLine(); vrp.RepeatRowSpan(); vrp.SetTemplateData("zj","合 计"); vrp.SetTemplateData("sjywl1","%ld",zj_sjywl); vrp.SetTemplateData("qs1",""); vrp.SetTemplateData("jqywl1","%.2f",zj_jqywl); vrp.SetTemplateData("yl1","%ld",zj_ylerr); vrp.SetTemplateData("el1","%ld",zj_elerr); vrp.SetTemplateData("sl1","%ld",zj_slerr); vrp.SetTemplateData("hj1","%ld",zj_hjerr); sjccl=double(zj_hjerr)/zj_sjywl; jqccl=double(zj_hjerr)/zj_jqywl; vrp.SetTemplateData("sjccl1","%.2f",sjccl*1000); vrp.SetTemplateData("jqccl1","%.2f",jqccl*1000); vrp.RepeatCurrentLine(); vrp.WriteTemplateFile(); vrp.SetWindowTitle("岗位业绩统计表"); vrp.SetPrintInfo("","","&p/&P"); vrp.Display(); return; }